import config
import random
from utils import *

def register():
	return RandomMember()

class RandomMember:
	def __init__(self):
		self.type = 'passive'
		self.help = \
'''随机选择：
	用法：
		*随机群员
	从群里随机选择一个群员。'''

	def run(self, gum, msg):
		if msg['type'] != 'GroupMessage' \
				or len(msg['messageChain']) <= 1 \
				or msg['messageChain'][1]['type'] != 'Plain' \
				or msg['messageChain'][1]['text'].split()[0] != '*随机群员':
			return

		if random.random() < 0.1:
			autoReply('糖糖不想选……', gum)
		else:
			data = get(par('memberList', target=here()))['data']
			member = random.choice(data)
			autoReply(member['memberName'] + '(' + str(member['id']) + ')', gum)